package  
{
	import flash.display.Sprite;
	//import flash.events.KeyboardEvent;
	/**
	 * ...
	 * @author 
	 */
	public class Map extends Sprite
	{
		public var mapH:uint = 50;
		public var mapW:uint = 80;
		private var mapArr:Array;
		//private var mapSpr:Sprite;
		public var startNode:Node;
		public var endNode:Node;
		public static const TILE_SIZE:uint = 8;
		public function Map() 
		{
			initMap();
			//mapSpr.addEventListener(KeyboardEvent.KEY_DOWN,flushMap);
		}
		private function initMap():void
		{
			mapArr = new Array();
			for (var i:int = 0; i < mapH; i++ )
			{
				mapArr[i] = new Array();
				for (var j:int = 0; j < mapW; j++ )
				{
					var node:Node = new Node(i, j);
					var isWalkAble:Boolean = (Math.random() > 0.9)?false:true;
					node.isWalkAble = isWalkAble;
					//trace(node.row,node.col);
					mapArr[i].push(node);
					//trace(node.isWalkAble);
				}
				mapArr.push(mapArr[i]);
			}
			this.startNode = mapArr[9][9] as Node;
			this.startNode.isWalkAble = true;
		}
		public function drawMap():void
		{
			//mapSpr = new Sprite();
			for (var i:int = 0; i < mapH; i++ )
			{
				for (var j:int = 0; j < mapW; j++ )
				{
					var node:Node = mapArr[i][j] as Node;
					var color:uint;
					if (node.isWalkAble)
					{
						color = 0xffffff;
					}
					else
					{
						color = 0;
					}
					graphics.lineStyle(0);
					graphics.beginFill(color);
					graphics.drawRect(j * TILE_SIZE, i * TILE_SIZE, TILE_SIZE, TILE_SIZE);
					graphics.endFill();
				}
			}
			//addChild(mapSpr);
		}
		public function getNode(row:uint, col:uint):Node
		{
			return mapArr[row][col] as Node;
		}
		
	}

}